var array = [
      
      2,4
   ];

function insert_sorted(input, list, insertLast) {

   var len = list.length;
   
   var min = 0;
   
   var max = len - 1;
   
   var value, index, c, l;
   
   while (min <= max) {
      
      index = (min + max) / 2 | 0;

      value = list[index];
      
      if (value < input) {
            
         min = index + 1;
         
      } else if (value > input) {
         
         max = index - 1;
         
      } else {
         
         // find last index with the same input
         if (insertLast) {
            
            
            
            
         }
         
         max = index;
         
         console.log('found insertion ', index, ' input: ', input);
         
         break;
         
      }
      
   }
   
   console.log('insert index: ', index, ' found? ', max, ' in ', list);
   
   return;
   
   
   
   
   
   
   
   if (len) {
      
      min = 0;
      
      max = len - 1;
      
      while (min <= max) {
         
         index = (min + max) / 2 | 0;
         
         value = list[index];
         
         console.log('index: ', index, ' from: ', min, ' to: ', max, '     value: ', value, ' find: ', input);
         
         if (value < input) {
            
            min = index + 1;
            
         } else if (value > input) {
            
            max = index - 1;
            
         } else {
            
            max = index;
            
            console.log('found? ', index, ' input: ', input);
            
            break;
            
         }
   
         
         maxExec--;
         
         if (!maxExec) {
            
            console.log('maxed out!');
            break;
            
         }
         
         
         
      }
      
      console.log('found: ', max);
   
   }
   
   console.log('! array: ['+ array.join(' , ') + ']  inserted at index: ' + anchor);
   
}












function binaryIndexOf(searchElement) {
	'use strict';

	var minIndex = 0;
	var maxIndex = this.length - 1;
	var currentIndex;
	var currentElement;
	var resultIndex;

	while (minIndex <= maxIndex) {
		resultIndex = currentIndex = (minIndex + maxIndex) / 2 | 0;
		currentElement = this[currentIndex];

		if (currentElement < searchElement) {
			minIndex = currentIndex + 1;
		}
		else if (currentElement > searchElement) {
			maxIndex = currentIndex - 1;
		}
		else {
			return currentIndex;
		}
	}

	return ~maxIndex;
}